"""
数据字典--分类
"""
import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool


@pytest.mark.基础管理系统
@pytest.mark.系统管理
def test_case(playwright : Playwright) -> None:

    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    page.goto(url+url_login)
    page.get_by_placeholder("请输入用户名").fill(username_admin)
    page.get_by_placeholder("请输入密码").fill(password_admin)
    page.get_by_role("button", name="登 录").click()
    page.get_by_text("UAT-环北部湾广西水资源配置工程").first.click()
    page.wait_for_timeout(1000)
    page.goto(url+url_shujuzidian)

    page.locator(".el-tooltip").first.click()
    page.get_by_role("dialog").get_by_role("button", name=" 新建").click()
    page.get_by_placeholder("请选择项目上级").click()
    page.get_by_text("顶级节点").click()
    page.get_by_role("dialog", name="新建").get_by_placeholder("请输入名称").fill("AutoTest字典分类")
    page.get_by_placeholder("请输入编码（编码规则采用大驼峰式命名法，例如：").fill("ZCZDFL")
    page.get_by_role("switch").locator("span").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("新建成功！")
    page.get_by_label("close 字典分类管理").click()
    page.get_by_placeholder("请输入名称回车键查询").fill("AutoTest字典分类")
    page.get_by_role("button", name="", exact=True).click()
    page.locator("#app").get_by_text("AutoTest字典分类").click()
    page.get_by_role("button", name=" 新建").click()
    page.get_by_placeholder("请输入字典名称").fill("AutoTest字典名称")
    page.get_by_placeholder("请输入字典编码（编码规则采用大驼峰式命名法，例如：").fill("ZCZDMC")
    page.wait_for_timeout(1000)
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("paragraph")).to_contain_text("新建成功！")
    page.wait_for_timeout(2000)
    page.get_by_role("button", name="删除").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("删除成功！")
    page.wait_for_timeout(2000)
    page.locator(".el-tooltip").first.click()
    page.get_by_role("dialog", name="字典分类管理").get_by_placeholder("请输入名称").fill("AutoTest字典分类")
    page.get_by_role("dialog").get_by_role("button", name=" 查询").click()
    page.wait_for_timeout(1000)
    page.get_by_role("button", name="删除").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("删除成功！")

    SetupTeardown.close()
